#!/usr/bin/env python
# -*- coding:utf8 -*-
"""
Author : mafei
Date   : 2019-12-07
"""
from apscheduler.schedulers.blocking import BlockingScheduler
from datetime import datetime
from mmonitor.common.config import mysql_db, mysql_password, mysql_server, mysql_user, mysql_port, rpc_port, rpc_host
from apscheduler.schedulers.background import BackgroundScheduler
import time
import logging

from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.memory import MemoryJobStore
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from sqlalchemy import create_engine
mysql_url = 'mysql+pymysql://%s:%s@%s:%s/%s?charset=utf8' % (mysql_user,
                                                             mysql_password,
                                                             mysql_server,
                                                             mysql_port,
                                                             mysql_db)
jobstores = {
    'default': SQLAlchemyJobStore(engine=create_engine(mysql_url,
                                                       encoding='utf-8',
                                                       pool_recycle=10,
                                                       echo=False))
}
sched = BlockingScheduler(timezone='Asia/Shanghai',
    jobstores=jobstores,
    job_defaults=dict(misfire_grace_time=24 * 3600))

def my_job():
    print('{datetime.now():%H:%M:%S} Hello World ')

# sched.add_job(my_job, 'interval', seconds=5)
sched.start()